import javax.print.*;
import java.awt.print.*;
import javax.swing.JOptionPane;
/*
 * MyFileChooser.java
 *
 * Created on June 12, 2006, 9:49 AM
 */

/**
 *
 * @author  yaco
 */
import javax.swing.filechooser.FileFilter;
import java.io.File;

public class MyFileChooser extends javax.swing.JFrame {
   int printFileChooserSelection;
    /** Creates new form MyFileChooser */
    public MyFileChooser() {
        initComponents();
        this.setSize(600,455);
        this.setLocation(250,200);
        
        MyFilter filter = new MyFilter(".mdif","MYSQL Document Imaging Format (*.mdif)");
        jFileChooser1.addChoosableFileFilter(filter); 
        jFileChooser1.setFileFilter(filter);
       
    }

  class MyFilter extends FileFilter {
      
    public MyFilter(String extension, String description) {
       this.extension = extension.toLowerCase(); 
       this.description = description; 
}
    public boolean accept(File file) {
        boolean isAccepted1=file.isDirectory();
        boolean isAccepted2=file.getName().toLowerCase().endsWith(extension);
        return (isAccepted1||isAccepted2);
}
    public String getDescription() {
        return description;
}
private String description; 
private String extension; 
  }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        jFileChooser1 = new javax.swing.JFileChooser();

        getContentPane().setLayout(null);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Save As");
        setResizable(false);
        jFileChooser1.setAcceptAllFileFilterUsed(false);
        jFileChooser1.setDialogType(javax.swing.JFileChooser.SAVE_DIALOG);
        jFileChooser1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jFileChooser1ActionPerformed(evt);
            }
        });
        jFileChooser1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jFileChooser1MouseClicked(evt);
            }
        });

        getContentPane().add(jFileChooser1);
        jFileChooser1.setBounds(0, 0, 590, 420);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jFileChooser1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jFileChooser1ActionPerformed
// TODO add your handling code here:
     if (printFileChooserSelection==jFileChooser1.APPROVE_OPTION){
         PrinterJob printerJob = PrinterJob.getPrinterJob();
         try{
         //printerJob.setPrintable();    
         printerJob.print();
         }catch(PrinterException ex){JOptionPane.showMessageDialog(null,"check your print device seetings","Error", JOptionPane.ERROR_MESSAGE);}
    }//GEN-LAST:event_jFileChooser1ActionPerformed

    }
    private void jFileChooser1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jFileChooser1MouseClicked
// TODO add your handling code here:       
    }//GEN-LAST:event_jFileChooser1MouseClicked
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                MyFileChooser myFileChooser=new MyFileChooser();
                myFileChooser.printFileChooserSelection=myFileChooser.jFileChooser1.showSaveDialog(null);
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    javax.swing.JFileChooser jFileChooser1;
    // End of variables declaration//GEN-END:variables
    
}
